package dth.bean;

import java.util.ArrayList;
import java.util.List;

import javax.faces.bean.ManagedBean;

import dth.dao.PaymentHistoryDAO;
import dth.entity.PaymentHistory;
import dth.utils.DthSessionConstant;
import dth.utils.DthUtil;

@ManagedBean(name="paymentBean")
public class PaymentBean {
	private List<PaymentHistory> listPaymentHistories=new ArrayList<PaymentHistory>();
	private int id;
	
	public int getId() {
		return id;
	}

	public void setId(int id) {
		this.id = id;
	}

	public List<PaymentHistory> getListPaymentHistories() {
		PaymentHistoryDAO dao=new PaymentHistoryDAO();
		listPaymentHistories=dao.getListPaymentHistory();
		System.out.println("--list payment size:"+listPaymentHistories.size());
		return listPaymentHistories;
	}

	public void setListPaymentHistories(List<PaymentHistory> listPaymentHistories) {
		this.listPaymentHistories = listPaymentHistories;
	}
	public PaymentBean() {
		System.out.println("---request url:"+DthUtil.getRequestURL());
		if(DthUtil.getRequestURL().contains("payment_history.xhtml")){
			System.out.println("--vao day role:"+LoginBean.roleCode);
			if(LoginBean.roleCode!=1)
				DthUtil.navigateTo("welcome.xhtml");
		}
		// TODO Auto-generated constructor stub
		System.out.println("---vao payment bean");
		Object objectAction = DthUtil.getRequest().getParameter("action");
		System.out.println("----------action:" + objectAction);
		if (objectAction != null) {
			if (objectAction.equals("delete")) {
				Object objectId = DthUtil.getRequest().getParameter("id");
				if (objectId != null)
				{
					id = Integer.parseInt(objectId.toString());
					
				}
					
			}
		}
	}
	public void delete(){
		try{
		PaymentHistoryDAO dao=new PaymentHistoryDAO();
		System.out.println("--delete id:"+id);
		int count=dao.delete(id);
		if (count > 0)
			DthUtil.showMessage("Mesage", "Update success");
		else
			DthUtil.showMessage("Message", "Update error");
		}
		catch(Exception ex){
			DthUtil.showMessage("Message", "Update error");
		}
			
	}
}
